<#include "/common/_layout.html"/>
<@layout>
<script>
	$(function() {
		$('#dg').datagrid({
			url:'/optional/paginate',
			rownumbers:true,
			pagination:true,
			pageList:[20,50,100],
			pageSize:20,
			fitColumns:true,
			singleSelect:true,
			columns:[[
				{field:'id',title:'id',hidden:true},
				{field:'stockCode',title:'股票代码'},
				{field:'stockUrl',title:'路径', 
					formatter: function(value, row, index) {
						return '<a target="_blank" href="http://quote.eastmoney.com/' + row.stockCode + '.html">http://quote.eastmoney.com/' + row.stockCode + '.html</a>';
					}},
				{field:'symbol',title:'日K线', width:400,
					formatter: function(value, row, index) {
						return '';
						//return '<img src="http://image.sinajs.cn/newchart/daily/n/' + value + '.gif"/>';
					}}
			]],
			onLoadSuccess:function(msg) {
				if('1' == msg.errCode) {
					openLoginWindow();
					return;
				}
			}
		});
	});
	
	function getData() {
		var stockCode = $('#stock_code').textbox('getValue');
		var searchUrl = "/stocksignal/paginate?stockCode=" + stockCode;
		$('#dg').datagrid({
			url:searchUrl,
			pageNumber:1
		});
	}
	
	//移除关注
	function removeOptional() {
		//获取选中的行
		var row = $('#dg').datagrid('getSelected');
		if(row == null) {
			$.messager.alert('错误','请选择数据后再进行操作!');
			return;
		}
		
		var obj = {
		  'id':row.id
		};
		page_post_ajax('/optional/remove', obj, 'removeCallback', '');
	}
	
	//添加回调函数
	function removeCallback(msg) {
		console.log(msg);
		if(1 == msg.errCode) {
			openLoginWindow();
			return;
		}
		if(2 == msg.errCode) {
			$.messager.alert('错误', msg.errMsg);
			return;
		}
		if(0 == msg.errCode) {
			$.messager.alert('提示','删除成功!');
			$('#dg').datagrid('reload');
			return;
		}
	}
</script>

<div class="table_box" style="padding-bottom: 5px">
	<!-- 导入工具栏 -->
	<#include "/common/_toolbar.html"/>
	<@toolbar toolbarArr = [['btn_add','icon-remove','removeOptional()','移除关注']]
	          optionArr = [{'id':'stock_code', 'label':'股票代码', 'type':'input', 'prompt':'请输入股票代码'}]/>
</div>

<table id="dg" style="height:698px"></table>
</@layout>